#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <arpa/inet.h>
#include <sys/socket.h>

#define BUF_SIZE 30

int main(int argc, char *argv[])
{
    int send_sock;
    struct sockaddr_in broad_addr;
    FILE *fp;
    char buf[BUF_SIZE];
    int so_brd = 1;

    send_sock = socket(AF_INET, SOCK_DGRAM, 0);
    memset(&broad_addr, 0, sizeof(broad_addr));
    broad_addr.sin_family = AF_INET;
    broad_addr.sin_addr.s_addr = inet_addr(argv[1]);
    broad_addr.sin_port = htons((uint16_t)atoi(argv[2]));

    setsockopt(send_sock, SOL_SOCKET, SO_BROADCAST, &so_brd, sizeof(so_brd));
    fp = fopen("sender.txt", "r");

    while(!feof(fp)) {
        fgets(buf, BUF_SIZE, fp);
        sendto(send_sock, buf, strlen(buf), 0, (const struct sockaddr *)&broad_addr, sizeof(broad_addr));
        sleep(2);
    }
    fclose(fp);
    close(send_sock);
    return 0;
}